package com.nulldev.util.web.YouTubeExtractor.formats.ecd.codecs;

import com.nulldev.util.VariableAPI.StringsUtil;
import com.nulldev.util.logging.Logger;
import com.nulldev.util.logging.LoggerFactory;

public enum AudioCodecs {

	/*
	 * Work in progress: YouTubeExtractor Extension: ECD (Enhanced Codec Data)
	 */

	UNKNOWN("N/A", 0, "N/A", "N/A"),

	OPUS("opus", 0, "Standard", "Opus (Xiph and IETF Opus)"),

	MP4_AAC("mp4a.40.1", 0, "Main", "AAC (Advanced Audio Codec) Main Profile"),
	MP4_AAC_LC("mp4a.40.2", 0, "Low-Complexity", "AAC (Advanced Audio Codec) Low-Complexity"),
	MP4_AAC_SSR("mp4a.40.3", 0, "Scalable Sampling Rate", "AAC (Advanced Audio Codec) Scalable Sampling Rate"),
	MP4_AAC_LTP("mp4a.40.4", 0, "Long Term Predictor", "AAC (Advanced Audio Codec) Long Term Predictor"),
	MP4_AAC_SBR("mp4a.40.5", 0, "Spectral Band Replication", "AAC (Advanced Audio Codec) Spectral Band Replication"),

	AC3("ac-3", 0, "Standard", "ATSC A/52 (Dolby Digital Audio)"),
	EAC3("ec-3", 0, "Standard", "ATSC A/52:2012 (Dolby Digital Plus Audio)")

	;

	private final String codecString;
	private final double dIdent;
	private final String stringIdent;
	private final String fullCodecString;

	private AudioCodecs(final String codecString, final double identifier, final String stringIdentifier, final String fullCodecString) {
		this.codecString = codecString;
		this.dIdent = identifier;
		this.stringIdent = stringIdentifier;
		this.fullCodecString = fullCodecString;
	}

	public String getCodecString() {
		return this.codecString;
	}

	public double getDoubleIdentifier() {
		return this.dIdent;
	}

	public String getStringIdentifier() {
		return this.stringIdent;
	}

	public String getFullCodecString() {
		return this.fullCodecString;
	}

	public static AudioCodecs getCodec(final String mime) {
		return UNKNOWN;
	}

	private static final Logger log = LoggerFactory.getLogger();

	public static AudioCodecs fromMime(final String mime) {
		if (mime == null || mime.isEmpty())
			return UNKNOWN;
		if (!mime.startsWith("audio/"))
			return UNKNOWN; // FIXME: We don't account for fallback videos.
		final String actualMime = StringsUtil.substringBetweenO(StringsUtil.cleanInvalidCharacters(mime), "\"", "\"");
		for (final AudioCodecs codec : values()) {
			if (codec.codecString.equalsIgnoreCase(actualMime))
				return codec;
		}
		log.warn("Unknown audio codec mime: " + actualMime);
		return UNKNOWN;
	}
}
